package org.example.source;

import org.apache.flink.api.common.eventtime.WatermarkStrategy;
import org.apache.flink.api.common.typeinfo.Types;
import org.apache.flink.api.connector.source.util.ratelimit.RateLimiterStrategy;
import org.apache.flink.connector.datagen.source.DataGeneratorSource;
import org.apache.flink.connector.datagen.source.GeneratorFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class DatagenDemo {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setParallelism(3);
        DataGeneratorSource dataGeneratorSource = new DataGeneratorSource<>((GeneratorFunction<Long, String>) aLong -> "NUMBER:" + aLong,
                100, RateLimiterStrategy.perSecond(1), Types.STRING);

        DataStreamSource datagen = env.fromSource(dataGeneratorSource, WatermarkStrategy.noWatermarks(), "datagen");
        datagen.print();
        env.execute("DatagemDemo");
    }
}
